package com.sshe.web.action;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import com.opensymphony.xwork2.ModelDriven;
import com.sshe.web.action.util.ActionUtil;
import com.sshe.web.model.User;

/**
 * 
 * @author 罗超(455723382@qq.com)<br/>
 *         2013-8-1 下午03:40:17
 */
public class LoginAction extends ActionUtil implements ModelDriven<User> {

	private static final long serialVersionUID = 3846336058462537111L;
	private User user = new User();
	private String tokenID;

	@Override
	public String execute() throws Exception {
		// PrintWriter out = getResponse().getWriter();
		// Map<String, Object> map = new HashMap<String, Object>();
		// map.put("name", "测试用户");
		// out.write(JSONSerializer.toJSON(map).toString());
		// out.flush();
		// out.close();
		getRequest().setAttribute("tokenID", new Random().nextInt(10000));
		return SUCCESS;
	}

	/**
	 * 临时测试<br/>
	 * 
	 * @return String
	 */
	public String test() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "测试用户");
		map.put("type", "json");
		writer(map);
		return SUCCESS;
	}

	/**
	 * 用户登录验证<br/>
	 * 
	 * @return String
	 */
	public String vaild() {
		System.out.println("LoginAction.vaild():" + user.getName() + "\t"
				+ user.getPwd());
		getRequest().setAttribute("Result", "鉴权结束,tokenID:" + tokenID);
		return SUCCESS;
	}

	@Override
	public User getModel() {
		return user;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getTokenID() {
		return tokenID;
	}

	public void setTokenID(String tokenID) {
		this.tokenID = tokenID;
	}

}
